package com.honestpeak.datafusion.web;

import com.honestpeak.core.datasource.DataSourceContextHolder;
import com.honestpeak.core.datasource.DataSourceType;
import com.honestpeak.datafusion.model.Dwh;
import com.honestpeak.datafusion.model.YearTerm;
import com.honestpeak.datafusion.service.HpamsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * @Auther: apple
 * @Date: 2018/8/11 15:17
 * @Description: 晨跑控制层
 */
@Controller
@RequestMapping("/hpams")
@Slf4j
public class HpamsController {

    @Autowired
    private HpamsService hpamsService;

    /**
     * 跳转晨跑健步的页面中
     * @param mav
     * @return
     */
    @RequestMapping(value = "/cpjbUI", method = RequestMethod.GET)
    public ModelAndView UI(ModelAndView mav){
        DataSourceContextHolder.setDbType(DataSourceType.HPAMS);
        //查询院系
        List<Dwh> dwhList = hpamsService.getDwInfo();
        //查询学年
        List<String> yearList = hpamsService.getYearTermInfo();
        log.info("dwInfo:{}", dwhList);
        mav.addObject("dwhList", dwhList);
        mav.addObject("yearList", yearList);
        mav.setViewName("hpams/cpjb");
        return mav;
    }

    @RequestMapping(value = "/getYxStuNumByDay", method = RequestMethod.GET)
    @ResponseBody
    public Object getXyStuNumByDay(@RequestParam(value = "day", required = false) String day){
        DataSourceContextHolder.setDbType(DataSourceType.HPAMS);
        Map<String, Object> resultMap = hpamsService.getXyStuNumByDay(day);
        return resultMap;
    }


    /**
     * 根据学年查询莫院系下的所有晨跑学生数量
     * @param year
     * @return
     */
    @RequestMapping(value = "/getXYStuNumByYear",method = RequestMethod.GET)
    @ResponseBody
    public Object getYXStuNumByYear(@RequestParam(value = "year", required = true) String year, @RequestParam(value = "dwh",required = true) String dwh){
        DataSourceContextHolder.setDbType(DataSourceType.HPAMS);
        List<Map<String, Object>> resultMap = hpamsService.getYXStuNumByYear(year, dwh);
        return resultMap;
    }

    /**
     * 晨跑月活动人数
     * @param year
     * @param dwh
     * @return
     */
    @RequestMapping(value = "/getMonthRunActiveCountByYearDwh", method = RequestMethod.GET)
    @ResponseBody
    public Object getMonthRunActiveCountByYearDwh(@RequestParam(value = "year", required = true) String year, @RequestParam(value = "dwh",required = true) Integer dwh){
        DataSourceContextHolder.setDbType(DataSourceType.HPAMS);
        return hpamsService.getMonthRunActiveCountByYearDwh(year, dwh);
    }


    /**
     * 晨跑周活动人数
     * @param year
     * @param dwh
     * @return
     */
    @RequestMapping("getHpamsActiveCount")
    @ResponseBody
    public Object getHpamsActiveCount(String year,String dwh){
        return hpamsService.getHpamsActiveCountByYearWeekDwh(year, dwh);
    }
}
